import React from 'react';
import { forwardRef, useState, useImperativeHandle } from 'react'
// useImperativeHandle
// 该hook 作用: 可以将当前组件中的数据和方法抛出来, 共父组件访问使用
// 语法: useImperativeHandle(ref,()=>{return {要抛出的内容}})
const Son = (props, ref) => {
    const [newuser, setNewUserFn] = useState({ name: '李四', age: 20 });
    useImperativeHandle(ref, () => {
        return {
            newuser,
            setNewUserFn
        }
    })

    return (
        <div>
            <p>子组件: {newuser.name}--{newuser.age}</p>
        </div>
    );
}

export default forwardRef(Son);
